from django.contrib import admin

from china_regions.list_filter import CityListFilter, CountryListFilter, TownListFilter, CountryList
from china_regions.models import Province, City, Country, Town


@admin.register(Province)
class ProvinceAdmin(admin.ModelAdmin):
    search_fields = ('name', 'code')
    list_filter = ('name',)
    list_display = ('name', 'code')


@admin.register(City)
class CityAdmin(admin.ModelAdmin):
    search_fields = ('name', 'code')
    list_filter = (CityListFilter,)
    list_display = ('name', 'code')


@admin.register(Country)
class CountryAdmin(admin.ModelAdmin):
    search_fields = ('name', 'city', 'code')
    list_filter = ('city__province__name', CountryListFilter,)
    list_display = ('name', 'city', 'code')
    change_form_template = 'area.html'


@admin.register(Town)
class TownAdmin(admin.ModelAdmin):
    search_fields = ('name', 'country', 'code')
    list_filter = ('country__city__province__name', CountryList, TownListFilter,)
    list_display = ('name', 'country', 'code')
    change_form_template = 'town.html'
